<?php
session_start();
include('lib/lib.php');
include('connado.php');
//include('authen.php');
header("Content-type: text/html; charset=utf-8");
$logfile = PAHTLOG."ajax_mmt-" . date("Y-m-d") . ".log";

$manager = $_REQUEST['manager'];
$supervisor = $_REQUEST['supervisor'];
$operator = $_REQUEST['operator'];
$location = $_REQUEST['location'];

writelog($logfile, "manager     : " . $manager);
writelog($logfile, "supervisor     : " . $supervisor);
writelog($logfile, "operator     : " . $operator);
writelog($logfile, "location     : " . $location);

$rtn = 0;

//delete 
$sql = "delete from mainternace where e_id=? ";
$stmt = $db->Prepare($sql);
$arr_pre = array($operator);

if($db->Execute($stmt, $arr_pre)){
	
	writelog($logfile, "delete mainternace success!");
	$lo_split = explode("@@", $location);
	for($i = 0; $i < sizeof($lo_split); $i++){
		$sql = "insert into mainternace(m_id, s_id, e_id, location_id)values(?, ?, ?, ?)";
		$stmt = $db->Prepare($sql);
		$arr_pre = array($manager, $supervisor, $operator, $lo_split[$i]);
		if($db->Execute($stmt, $arr_pre)){
			writelog($logfile, "insert mainternace success!");
			$rtn++;
		}else{
			writelog($logfile, "insert mainternace error!");
		}
	}
}else{
	writelog($logfile, "delete mainternace error!");
}




writelog($logfile, "reply : $xml");
writelog($logfile, "-------------------------------------------------- ");

echo $rtn;
?>

